import functools

# 公用的自定义工具类
from flask import current_app
from flask import g
from flask import session

from info.models import User


def to_index_class(index):
    """返回指定索引对应的类名"""

    if index == 0:
        return 'first'
    if index == 1:
        return  'second'
    if index == 2:
        return  'third'

    return ''


# 这里ｆ是new_detail
def user_login_data(f):
    @functools.wraps(f)
    def wrapper(*args,**kwargs):
        user_id = session.get("user_id", None)
        user = None
        if user_id:
            # 尝试查询用户的模型
            try:
                user = User.query.get(user_id)
            except Exception as d:
                current_app.logger.error(d)
        g.user = user
        return f(*args,**kwargs)
    return wrapper



